﻿
function AccountViewModel() {
    var self = this;
    self.UserName = ko.observable();

    self.ResetPassword = function () {

        
        var myData = ko.toJSON(self);
        
        jQuery.ajax({
            url: "./Account/PasswordResetRequest/",
            type: 'post',
            data: myData,
            contentType: 'application/json',
            success: function (result) {
                $('#success-dis').text('Password reset link has been sent to your email');
                $('#register-error').css({ 'display': 'none' });
                $('#success-msg').css({ 'display': 'block' });
                $(document).scrollTop(0);
            },
            error: function (xhr, ajaxOptions, thrownError) {
                $('#success-msg').css({ 'display': 'none' });
                $('#register-error').css({ 'display': 'block' });
                $('#error-dis').text(thrownError);
                
                $(document).scrollTop(0);
            }
        });
    };

    function flash(el) {

        el.addClass('selected');
        window.setTimeout(function () {
            el.removeClass('selected');
        }, 3000);
    }

    ko.bindingHandlers.enterkey = {
        init: function (element, valueAccessor, allBindingsAccessor, viewModel) {
            var inputSelector = 'input,textarea,select';
            $(document).on('keypress', inputSelector, function (e) {
                var allBindings = allBindingsAccessor();
                $(element).on('keypress', 'input, textarea, select', function (e) {
                    var keyCode = e.which || e.keyCode;
                    if (keyCode !== 13) {
                        return true;
                    }

                    
                });
            });
        }
    };



}

function AccountNewPasswordViewModel() {
    var self = this;

    self.NewPassword = ko.observable();
    //self.ConfPassword = ko.observable();
    
    self.ResetPasswordAction = function () {
        //alert('Reset password action script');

        var myData = ko.toJSON(self);

        jQuery.ajax({
            url: "./Account/PasswordResetAction/",
            type: "post",
            data: myData,
            contentType: "application/json",
            success: function (result) {
                $("#Main").html(result);
            }
        });
    };
}